"""
右侧内容组件
"""
from PyQt6.QtWidgets import QStackedWidget, QLabel, QVBoxLayout, QWidget
from PyQt6.QtCore import Qt
from .account_page import AccountPage
from .scan_account_page import ScanAccountPage
from .task_page import TaskPage
from .statistics_page import StatisticsPage


class ContentWidget(QStackedWidget):
    """右侧内容组件类"""
    
    def __init__(self, parent=None):
        super().__init__(parent)
        # 初始化页面字典
        self.pages = {}
        self.setup_ui()
    
    def setup_ui(self):
        """初始化UI"""
        self.setStyleSheet("""
            ContentWidget {
                background-color: #f0f2f5;
                border-left: 1px solid #dcdcdc;
            }
        """)
        
        # 创建默认页面
        default_page = QWidget()
        layout = QVBoxLayout(default_page)
        label = QLabel("请从左侧菜单选择功能")
        label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        layout.addWidget(label)
        self.addWidget(default_page)
        
        # 创建统计页面
        statistics_page = StatisticsPage()
        self.addWidget(statistics_page)
        self.pages["统计"] = 1  # 存储页面索引
        
        # 创建账号管理页面
        account_page = AccountPage()
        self.addWidget(account_page)
        self.pages["下单账号管理"] = 2  # 存储页面索引
        
        # 创建扫货账号管理页面
        scan_account_page = ScanAccountPage()
        self.addWidget(scan_account_page)
        self.pages["扫货账号管理"] = 3  # 存储页面索引
        
        # 创建任务管理页面
        task_page = TaskPage()
        self.addWidget(task_page)
        self.pages["任务管理"] = 4  # 存储页面索引
    
    def switch_to_page(self, page_name, page_widget=None):
        """切换到指定页面"""
        if page_widget is not None:
            # 如果提供了页面部件，添加到堆栈中
            if page_name not in self.pages:
                self.addWidget(page_widget)
                self.pages[page_name] = self.count() - 1
            self.setCurrentIndex(self.pages[page_name])
        elif page_name in self.pages:
            self.setCurrentIndex(self.pages[page_name])
        else:
            # 如果页面不存在，显示默认页面
            self.setCurrentIndex(0)
